<template>
    <div>
        <el-dialog title="审核" :visible="true" width="600px" :modal-append-to-body="false" :close-on-click-modal="false"
            @close="handleClose">
            <el-form id="forms" ref="forms" :rules="rulesModel" :model="form" label-width="100px">
                <el-form-item label="审核状态" prop="state">
                    <el-select v-model="form.state" style="width: 150px;" @change="e => { form.econtent = '' }">
                        <el-option label="通过" :value="1" />
                        <el-option label="驳回" :value="3" />
                    </el-select>
                </el-form-item>
                <el-form-item label="驳回理由" prop="econtent" v-if="form.state == 3">
                    <el-input v-model="form.econtent" placeholder="请输入驳回理由" />
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="handleClose">取 消</el-button>
                <el-button :loading="buttonLoading" type="primary" @click="submit()">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { sorder_SetState } from "@/api/sorder.js";
export default {
    props: {
        info: {
            default: {},
            type: Object
        },
    },
    data() {
        return {
            form: {}, // 详情实体
            rulesModel: {
                econtent: [
                    { required: true, message: '请输入驳回原因', trigger: 'blur' }
                ],
            },
            buttonLoading: false,
        }
    },

    mounted() {
        this.setForm();
    },
    methods: {
        /**关闭弹窗 */
        handleClose() {
            this.$parent.modalStatus = 0
        },
        /**表单参数初始化 */
        setForm() {
            this.form = {
                orderid: this.info.id,
                state: 1,
                econtent: '',
            };
        },
        /**（提交） */
        async submit() {
            try {
                try {
                    await this.$refs['forms'].validate()
                } catch (e) {
                    console.log(e)
                    return
                }
                const { success, msg } = await sorder_SetState(this.form)
                if (success) {
                    this.handleClose();
                }
                this.$message({
                    message: msg,
                    type: success ? 'success' : 'error'
                })
            } catch (e) {
                // 取消
                console.log(e)
            }
        },
    }
}
</script>

<style lang="scss" scoped>
.grid2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
}
</style>